﻿using Gx.Bll.Manage;
using Gx.ColdWarehouseErp.Controllers;
using Gx.Common;
using Gx.Model.Entity;
using Gx.Model.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Gx.ZhiChengXianWei.Controllers
{
    public class CustomerController : BaseController
    {
        LKCustomerBll customerBll = new LKCustomerBll();
        //
        // GET: /Customer/

        public ActionResult List()
        {
            return View();
        }

        /// <summary>
        /// 客户列表
        /// </summary>
        /// <param name="customerInput"></param>
        /// <returns></returns>
        public JsonResult GetCustomerPageList(CustomerInput customerInput)
        {
            var result = customerBll.GetCustomerPageList(customerInput);
            return JsonList(result.Total, result.List.ToArray());
        }

        /// <summary>
        /// 新增客户
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public JsonResult AddCustomer(LKCustomer customer)
        {
            var result = customerBll.AddCustomer(customer);
            string message = result ? "新增成功" : "新增失败";
            return Json(result, message);
        }

        /// <summary>
        /// 编辑客户
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public JsonResult EditCustomer(LKCustomer customer)
        {
            var result = customerBll.EditCustomer(customer);
            string message = result ? "编辑成功" : "编辑失败";
            return Json(result, message);
        }

        /// <summary>
        /// 删除客户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteCustomer(int id)
        {
            var result = customerBll.DeleteCustomer(id);
            string message = result ? "删除成功" : "删除失败";
            return Json(result, message);
        }
    }
}
